<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var groupAnagrams = function (strs) {
            let myMap = new Map()
            let res = []
            for (let i = 0; i < strs.length; i++) {
                let str = strs[i].split('').sort().join('')
                if(i==0){
                    myMap.set(str,[strs[i]])
                }else{
                    if (myMap.has(str)) {
                        myMap.get(str).push(strs[i])
                    }else{
                        myMap.set(str,[strs[i]])
                    }
                }
            }
            for (let [key, value] of myMap) {
                res.push(value)
            }
            return res
        };
        groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"])
    </script>
</body>

</html>